class Solution {
    public int lengthOfLongestSubstring(String s) {


        char[] arr=s.toCharArray();

        int[] hash=new int[128];
        int left=0;
        int right=0;
        int count=0;
        int c=0;

        while(right<arr.length){
            c=arr[right];

            if(hash[c]!=0){
                count=Math.max(count,right-left);

                while(right<arr.length && arr[left]!=arr[right]){
                    hash[arr[left]]--;
                    left++;
                };
                hash[arr[left++]]--;
            }

            hash[c]++;
            right++;
        }
        count=Math.max(count,right-left);




        return count;


    }
}



class Solution {
    public int lengthOfLongestSubstring(String s) {


        char[] arr=s.toCharArray();

        int[] hash=new int[128];
        int left=0;
        int right=0;
        int count=0;

        while(right<arr.length){
            int c=arr[right];


            while(hash[c]==0){

                hash[c]++;
                right++;

                if(right>=arr.length) break;
                c=arr[right];

            }
            count=Math.max(count,right-left);

            while(right<arr.length && arr[left]!=arr[right]){
                hash[arr[left]]--;
                left++;
            }

            left++;
            right++;

        }

        return count;


    }
}